using System;
using System.Collections.Generic;

namespace UnityEngine.Recorder
{
	[ExecuteInEditMode]
	public abstract class RecorderSettings : ScriptableObject
	{
		[SerializeField]
		private string m_AssetID;

		public int m_CaptureEveryNthFrame = 1;

		public FrameRateMode m_FrameRateMode = FrameRateMode.Constant;

		[Range(1f, 120f)]
		public double m_FrameRate = 30.0;

		public EFrameRate m_FrameRateExact = EFrameRate.FR_CUSTOM;

		public int m_StartFrame;

		public int m_EndFrame = 10;

		public float m_StartTime;

		public float m_EndTime = 1f;

		public DurationMode m_DurationMode;

		public bool m_SynchFrameRate = true;

		public FileNameGenerator m_BaseFileName;

		public OutputPath m_DestinationPath;

		[SerializeField]
		private InputSettingsList m_InputsSettings = new InputSettingsList();

		[SerializeField]
		private string m_RecorderTypeName;

		public InputSettingsList inputsSettings => m_InputsSettings;

		public string assetID
		{
			get
			{
				return m_AssetID;
			}
			set
			{
				m_AssetID = value;
				m_InputsSettings.ownerRecorderSettingsAssetId = value;
			}
		}

		public Type recorderType
		{
			get
			{
				if (string.IsNullOrEmpty(m_RecorderTypeName))
				{
					return null;
				}
				return Type.GetType(m_RecorderTypeName);
			}
			set
			{
				m_RecorderTypeName = ((value != null) ? value.AssemblyQualifiedName : string.Empty);
			}
		}

		public bool fixedDuration => m_DurationMode != DurationMode.Manual;

		public virtual bool isPlatformSupported => true;

		public RecorderSettings()
		{
			m_DestinationPath.root = OutputPath.ERoot.Current;
			m_DestinationPath.leaf = "Recordings";
		}

		public virtual bool ValidityCheck(List<string> errors)
		{
			bool result = true;
			if (m_InputsSettings != null)
			{
				List<string> errors2 = new List<string>();
				if (!m_InputsSettings.ValidityCheck(errors2))
				{
					errors.Add("Input settings are incorrect.");
					result = false;
				}
			}
			if (Math.Abs(m_FrameRate) <= 1.4012984643248171E-45)
			{
				result = false;
				errors.Add("Invalid frame rate.");
			}
			if (m_CaptureEveryNthFrame <= 0)
			{
				result = false;
				errors.Add("Invalid frame skip value");
			}
			if (!isPlatformSupported)
			{
				errors.Add("Current platform is not supported");
				result = false;
			}
			return result;
		}

		public virtual void OnEnable()
		{
			m_InputsSettings.OnEnable(m_AssetID);
			BindSceneInputSettings();
		}

		public void BindSceneInputSettings()
		{
			if (m_InputsSettings.hasBrokenBindings)
			{
				m_InputsSettings.Rebuild();
				if (m_InputsSettings.hasBrokenBindings)
				{
					UnityEngine.Debug.LogError("Recorder: missing input settings");
				}
			}
		}

		public virtual void OnDestroy()
		{
			if (m_InputsSettings != null)
			{
				m_InputsSettings.OnDestroy();
			}
		}

		public abstract List<RecorderInputSetting> GetDefaultInputSettings();

		public T NewInputSettingsObj<T>(string title) where T : class
		{
			return NewInputSettingsObj(typeof(T), title) as T;
		}

		public virtual RecorderInputSetting NewInputSettingsObj(Type type, string title)
		{
			RecorderInputSetting recorderInputSetting = (RecorderInputSetting)ScriptableObject.CreateInstance(type);
			recorderInputSetting.m_DisplayName = title;
			recorderInputSetting.name = Guid.NewGuid().ToString();
			return recorderInputSetting;
		}

		public abstract List<InputGroupFilter> GetInputGroups();

		public virtual bool SelfAdjustSettings()
		{
			return false;
		}
	}
}
